package com.gnerv.pabu.basic.core.dto;

import com.gnerv.pabu.basic.core.entity.RoleAuthorization;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础平台-角色授权 DTO
 *
 * @author gnerv
 * @date 2019/11/29
 **/
@Data
@NoArgsConstructor
public class RoleAuthorizationDTO {

    private Integer userType;
    private List<String> userIds;

    private Integer orgType;
    private List<String> orgIds;

    private Integer roleType;
    private List<String> roleIds;

    public List<RoleAuthorization> convert(String roleId, Integer type, String ukId) {
        List<RoleAuthorization> list = new ArrayList<>(30);
        RoleAuthorization roleAuthorization = new RoleAuthorization(roleId, type, ukId);
        list.add(roleAuthorization);
        switch (type) {
            case 1:
                if(CollectionUtils.isEmpty(this.userIds)){
                    break;
                }
                for (String userId : this.userIds) {
                    roleAuthorization = new RoleAuthorization(roleId, type, userId);
                    list.add(roleAuthorization);
                }
                break;
            case 2:
                if(CollectionUtils.isEmpty(this.orgIds)){
                    break;
                }
                for (String orgId : this.orgIds) {
                    roleAuthorization = new RoleAuthorization(roleId, type, orgId);
                    list.add(roleAuthorization);
                }
                break;
            case 3:
                if(CollectionUtils.isEmpty(this.roleIds)){
                    break;
                }
                for (String otherRoleId : this.roleIds) {
                    roleAuthorization = new RoleAuthorization(roleId, type, otherRoleId);
                    list.add(roleAuthorization);
                }
                break;
            default:
                break;
        }
        return list;
    }

}
